home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / connect-isdn.cgi.z / connect-isdn.cgi
Encoding:
Text File  |  1997-07-30  |  8.3 KB  |  257 lines

  1. #!/usr/bin/perl5
  2. #
  3. # connect-isdn.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: connect-isdn.cgi,v 1.26 1997/04/17 23:43:38 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.connect-start.cgi",10,10); } 
  25.  
  26. $myname = "connect-isdn.cgi";
  27. $temp = "task.tmp";
  28. $action= "connect-isdn.cgi?loop";
  29.  
  30. $it = "<td align=right><font size=4>";
  31. $ni = "</font></td>";
  32. $bo = "<td><font size=5><i>";
  33. $nb = "</i></font></td>";
  34.  
  35. @find_vals = ('switchtype','phone','spid1','spid2');
  36.  
  37. &get_fields;
  38.  
  39. if ($ARGV[0] eq 'loop') { %vals = %fld; }
  40. else { &readValues; }
  41.  
  42. if ($ARGV[0] eq loop) {
  43.     &errorCheck;
  44.     &writeFile;
  45.  
  46.     $go = "/tasks/connect-end.cgi?i";
  47.     #printf("Location: %s%c%c",$go,10,10); 
  48.     print "Content-type: text/html\n\n";
  49.     print "<HTML><HEAD>";
  50.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  51.     print "</HEAD><BODY></BODY></HTML>";
  52.     exit 0;
  53. }
  54.  
  55.  
  56. &generic;
  57.  
  58. sub readValues {
  59.     open(IN,"< $temp");
  60.     while(<IN>) {
  61.         @items = split(/=/);
  62.         foreach $arg (@find_vals) {
  63.             if ($arg eq $items[0]) { 
  64.                 if ($items[1] ne "\n") {
  65.                     $vals{$arg} = $items[1];
  66.                     chop $vals{$arg};
  67.                 }
  68.             }
  69.         }
  70.     }
  71.     close(IN);
  72. }
  73.  
  74. sub errorCheck {
  75.     &error("Phone number required.") if !$fld{'phone'};
  76.     &error("Invalid phone number.") if &check_phone($fld{'phone'});
  77.     if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
  78.         &error("Two SPID numbers required for switch type $fld{'switchtype'}.")
  79.         if (!$fld{'spid1'} || !$fld{'spid2'});
  80.         &error("Invalid SPID number: $fld{'spid1'}.") if $fld{'spid1'} =~ /[^0-9]/;
  81.         &error("Invalid SPID number: $fld{'spid2'}.") if $fld{'spid2'} =~ /[^0-9]/;
  82.     }
  83. }
  84.  
  85. sub error {
  86.     $error = $_[0];
  87.     &generic;
  88.     exit 0;
  89. }
  90.     
  91. sub writeFile {
  92.     $fld{'phone'} =~ s/\(//g;
  93.     $fld{'phone'} =~ s/\)//g;
  94.     $fld{'phone'} =~ s/\-//g;
  95.     $fld{'phone'} =~ s/\,//g;
  96.     $fld{'phone'} =~ s/ //g;
  97.  
  98.     undef %terms;
  99.     open(IN,"< $temp");
  100.     while(<IN>) {
  101.         @items = split(/=/);
  102.         chop $items[1];
  103.         $terms{$items[0]} = $items[1];
  104.     }
  105.     close(IN);
  106.     foreach $arg (@find_vals) {
  107.         if ($fld{$arg} eq "NET3/DSS1") { $terms{$arg} = "NET3"; next; }
  108.         $terms{$arg} = $fld{$arg};
  109.     }
  110.     open(OUT,"> $temp");
  111.     foreach $arg (keys(%terms)) {
  112.         print OUT "$arg=$terms{$arg}\n";
  113.     }
  114.     close(OUT);
  115. }
  116.  
  117. sub generic {
  118.     print "Content-type: text/html\n\n";
  119.     print "<html><head><title>ISDN Configuration</title>\n";
  120.     print "<script language=\"JavaScript\">\n<!--\n";
  121.  
  122.     # JavaScript
  123. print "function Next()  {
  124.     form = document.isdn;
  125.     if (!testPhone(form)) return;
  126.     if (!testSwitch(form)) return;
  127.     setTimeout('form.submit()',0);
  128.     return;
  129. }\n";
  130. print "function Previous()  {
  131.     setTimeout('window.location=\"connect-second.cgi?i\"',0);
  132.     return;
  133. }\n";
  134. print "function testPhone(form) { 
  135.     Ctrl = form.phone;
  136.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"The phone number is required.\"); return (false); } 
  137.     error = testPhoneChars(Ctrl.value);
  138.     if (error == 1) { errorBox (Ctrl, \"The phone number cannot contain spaces.\"); return (false); } 
  139.     if (error == 2) { errorBox (Ctrl, \"The phone number cannot contain \\nletters or punctuation.\"); return (false); } 
  140.     return (true);
  141. }\n";
  142. print "function testPhoneChars(word) {
  143.     for(i = 0; i < word.length; i++) {
  144.         c = word.charAt(i);
  145.         if (c == ' ') return 1;
  146.         if (c != \'(\' && c != \')\' && c != \'-\' && c != \',\') {
  147.             num = parseInt(c);
  148.             if(isNaN(num)) return 2;
  149.         }
  150.     } return 0;
  151. }\n";
  152. print "function testSwitch(form) {
  153.     Ctrl = form.switchtype; selnum = Ctrl.selectedIndex;
  154.     selected = Ctrl.options[selnum].text;
  155.     if (selected == \"DMS100\" || selected == \"NI1\") {
  156.         word1 = form.spid1.value; word2 = form.spid2.value;
  157.         if(word1 == \"\" || word2 == \"\") {
  158.             errorBox (Ctrl, \"Two SPID numbers are required for \\nswitch type \" + selected); return (false);
  159.         }
  160.         for(i=0; i < word1.length; i++) {
  161.             if(isNaN(parseInt(word1.charAt(i)))) {
  162.                 errorBox (Ctrl, \"Invalid SPID number: \" + word1); return (false);
  163.             }
  164.             if(isNaN(parseInt(word2.charAt(i)))) {
  165.                 errorBox (Ctrl, \"Invalid SPID number: \" + word2); return (false);
  166.             }
  167.         }
  168.     } 
  169.     return (true);
  170. }\n";
  171. print "function errorBox (Ctrl, ErrorMessage) {
  172.     alert (ErrorMessage);  Ctrl.focus();  return;
  173. }\n";
  174.  
  175. print "//-->\n";
  176. print "</script></head>\n\n";
  177.  
  178.     print "<body bgcolor=\'c7ded4\' background=/tasks/connect-task.bg.gif>\n";
  179.  
  180.     if ($error) {
  181.         print "<font size=4 color=ff0000><b>Error: </b>$error<br></font>";
  182.     }
  183.     print "<i>$message</i>";
  184.  
  185.     print "<table width=100%>",
  186.           "<tr><th align=left><h1>ISDN Configuration</h1></th>\n",
  187.           "<th align=right><a href=\"/newsplash.shtml\">",
  188.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  189.           "  <a href=\"/tasks/Tasks.shtml\">",
  190.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  191.           "</tr></table>\n";
  192.  
  193.     printf("<form name=\"isdn\" action=\"%s\" method=post>\n", $action);
  194.     
  195.     print "<center><table width=620>";
  196.  
  197.     print "<tr>$bo Phone number of your service provider: $nb \n$it",
  198.           &text("phone",$vals{'phone'},15), 
  199.           "$ni </tr>\n";
  200.     print "    <tr><td colspan=2>
  201.     To connect to the Internet, the Gateway places a call over the ISDN 
  202.     line to a host at the service provider's site. The phone number is 
  203.     required to reach the host, just as a phone number is required for 
  204.     a standard voice call. (Your ISP supplies this phone number.)  Do 
  205.     not include any punctuation symbols or spaces with the number.
  206.     </td></tr><tr><td> </td></tr>\n\n";
  207.  
  208.     print "<tr>$bo Switch used by your service provider: $nb \n$it", 
  209.         &select("switchtype",$vals{'switchtype'},
  210.         'DMS100',
  211.         'NI1',
  212.         '5ESS',
  213.         'NTT',
  214.         'NET3/DSS1',
  215.         '1TR6',
  216.         'VN3',
  217.         'TPH'), 
  218.         "$ni </tr>\n";
  219.     print "    <tr><td colspan=2>
  220.     Your ISDN configuration must be set to the type of switching equipment
  221.     that your ISDN provider uses. This options menu contains a list of 
  222.     commonly used switch types from which to select. (Switch types, and 
  223.     the additional information that some switches require, are specified 
  224.     by your ISDN provider.)
  225.     </td></tr><tr><td> </td></tr>\n\n";
  226.  
  227.     print "</table></center><center><table width=620>";
  228.  
  229.     print "<tr>$bo SPID numbers: $nb \n$it",
  230.           &text("spid1",$vals{'spid1'},15), "$ni $it\n",
  231.           &text("spid2",$vals{'spid2'},15), 
  232.           "$ni </tr>\n";
  233.     print "    <tr><td colspan=3>
  234.     If your provider uses DMS100 or NI1 switches, SPID numbers are 
  235.     required.  These numbers identify the available services on your 
  236.     ISDN line. (Your ISDN provider supplies SPID numbers.)
  237.     </td></tr><tr><td> </td></tr>\n";
  238.     print "</table></center>\n";
  239.  
  240.     print '<MAP NAME="js_map1">',
  241.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  242.     onMouseOver="window.status=\'\';return true">',
  243.     '</MAP>';
  244.     print "\n";
  245.     print '<MAP NAME="js_map2">',
  246.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()"
  247.     onMouseOver="window.status=\'\';return true">',
  248.     '</MAP>';
  249.     print "\n";
  250.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map2" align="right">';
  251.     print "\n";
  252.     print '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" align="right">';
  253.  
  254.     print "\n</form></body></html>";
  255. }
  256.  
  257.